<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>任务列表</title>
  <link rel="shortcut icon" href="/img/favicon.ico"/>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/common/layuimini/layui.css" media="all">
  <link rel="stylesheet" href="/common/layuimini/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
  <div class="layuimini-main">
    <fieldset class="table-search-fieldset">
      <legend>搜索信息</legend>
      <div style="margin: 10px 10px 10px 10px">
        <div class="layui-form layui-form-pane">
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">任务名称</label>
              <div class="layui-input-inline">
                <input type="text" name="articleTitle" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">任务组别</label>
              <div class="layui-input-inline">
                <input type="text" name="articleTitle" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-inline">
              <label class="layui-form-label">任务状态</label>
              <div class="layui-input-inline">
                <input type="text" name="articleAuthor" autocomplete="off" class="layui-input">
              </div>
            </div>
            <div class="layui-inline">
              <button id="queryArticle" type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
            </div>
          </div>
        </div>
      </div>
    </fieldset>


    <table id="taskTable" lay-filter="taskTable"></table>
    <script type="text/html" id="toolBar">
      <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
      <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
    </script>
  </div>
</div>
</body>
<script type="text/html" id="currentTableBar">
  <div class="layui-btn-container">
            <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
    <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>
    <!--        <button class="layui-btn layui-btn-sm layui-btn-primary layui-border-green " lay-event="import"> 导入 </button>-->
  </div>
</script>
<script type="text/javascript" src="/common/layui/layui.js"></script>
<script type="text/javascript" src="/common/jquery-1.11.3.js"></script>
<script>
  layui.use(['jquery','form','table'],function (){
    var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            util = layui.util;
    table.render({
      elem: "#taskTable",
      url: "/admin/task/table",
      toolbar: "#currentTableBar",
      id: "currentTaskTable",
      cols:[
              [
                {type: 'checkbox'},
                {field: '', title: '序号',width:60,templet:function (d){
                    return d.LAY_INDEX;
                  }},
                {field: 'jobName', title: '任务名', width: 150},
                // {field: 'jobGroup', title: '任务组名', width: 110,templet:function (d){
                //   if (d.jobGroup == 'DEFAULT'){
                //     return '默认';
                //   }else {
                //     return d.jobGroup;
                //   }
                //   }},
                {field: 'invokeTarget', title: '调用方法路径', width: 300},
                {field: 'cronExpression', title: 'cron', width: 110},
                {field: 'remark', title: '任务描述', width: 110},
                {field: 'status', title: '状态', width: 100,templet:function (d){
                    if (d.status == '0'){
                      return '<input type="checkbox" value="'+d.jobId+'"checked="" name="open" lay-skin="switch" lay-filter="changeJobState" lay-text="ON|OFF">'
                    }else {
                      return '<input type="checkbox" value="'+d.jobId+'"name="open" lay-skin="switch" lay-filter="changeJobState" lay-text="ON|OFF">'
                    }
                  }},
                {field: 'createTime', title: '创建时间', width: 200},
                {fixed: 'right', title:'操作', toolbar: '#toolBar', width:120}
              ]
      ]
    })

    //表格状态开关
    form.on('switch(changeJobState)', function(obj){
      console.log(this);
      var jobId = this.value;
      var checked = this.checked;
      var sign = '';
      if (checked){//启用
        sign = 'ON';
      }else {//停止
        sign = 'OFF';
      }
      $.ajax({
        type: "post",
        url: "/admin/task/changeJobState",
        data:{
          "jobId": jobId,
          "sign": sign
        },
        success:function (res){
          if (res.state == true){
            if (sign == 'ON'){
              layer.msg('已启用',{icon:1,time:800})
            }else {
              layer.msg('已停用',{icon:1,time:800})
            }
          }else {
            layer.msg(res.msg,{icon:2,time:800})
            if (sign == 'ON'){
              obj.elem.checked = false;
            }else {
              obj.elem.checked = true;
            }
            form.render();
          }
        }
      })


    });


    table.on('toolbar(taskTable)',function (obj){
      if (obj.event == 'add') {
        if (obj.event === 'add') {  // 监听添加操作
          var index = layer.open({
            title: '<h3>任务添加</h3>',
            type: 2,
            shade: 0.2,
            maxmin: true,
            shadeClose: true,
            anim: 2,
            area: ['80%', '80%'],
            content: '/admin/task/add',
          });
        } else if (obj.event == 'delete') {
          alert("delete");
        }
      }
    })
  });
</script>
</html>